home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 22 code / PCI Driver Sample / Print NCR Script / PrintNCRScript.c < prev   
Encoding:
C/C++ Source or Header  |  1995-07-27  |  5.2 KB  |  204 lines  |  [TEXT/MPCC]

  1. /*                                    PrintNCRScript.c                                */
  2. /*
  3.  * PrintNCRScript.c
  4.  * Copyright © 1995 Apple Computer Inc. All Rights Reserved.
  5.  */
  6. /*    .___________________________________________________________________________________.
  7.       | This dumps the NCR Script. It must be run immediately after system restart.        |
  8.       | It supports only one device.                                                        |
  9.     .___________________________________________________________________________________.
  10.  */
  11. #include <NCRDriverPrivate.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #define NOP                    0x80000000            /* Jump never                        */
  15. #define OP_MASK                (bit31 | bit30)        /* Select the operator type            */
  16. #define IO_OP                (bit30)
  17. #define JUMP_OP                (bit31)
  18. #define MEMORY_MOVE_OP        (bit31 | bit30)
  19. #define OPCODE(op)            ((op) & OP_MASK)
  20. #define IsMemoryMoveOp(op)    (OPCODE(op) == MEMORY_MOVE_OP)
  21. #define IsLabel(op)            ((op) == NOP)
  22.  
  23. DriverGlobalPtr                gDriverGlobalPtr;
  24. Boolean                        gScriptSetup = FALSE;
  25. OSErr                        GetDriverGlobalPtr(void);
  26. void                        PrintNCRScript(void);
  27. Boolean                        HasLabel(
  28.         UInt32                    opcode
  29.     );
  30.  
  31. void
  32. main(void)
  33. {
  34.         OSErr                status;
  35.         
  36.         status = GetDriverGlobalPtr();
  37.         if (status != noErr)
  38.             printf("Can't get Driver Global Information: status %d\n", (int) status);
  39.         else {
  40.             PrintNCRScript();
  41.         }
  42.         fclose(stdout);
  43. }
  44.  
  45. void
  46. PrintNCRScript(void)
  47. {
  48.         UInt32                    *ncrScriptPtr;
  49.         ByteCount                ncrScriptSize;
  50.         int                        i;
  51.         short                    size;
  52.         Boolean                    isLabel;
  53.         UInt32                    dcmd;
  54.         UInt32                    dsps;
  55.         UInt32                    temp;
  56.         UInt32                    pc;
  57.         short                    opSize;
  58.         
  59.         printf("•\n••• SCSI Script\n•\n");
  60.         ncrScriptPtr = gDriverGlobalPtr->ncrSCSIScript;
  61.         ncrScriptSize = gDriverGlobalPtr->ncrSCSIScriptSize;
  62.         size = (ncrScriptSize / sizeof (UInt32));
  63.         printf("Script at %08lx, size %ld\n",
  64.             (unsigned long) ncrScriptPtr,
  65.             (signed long) ncrScriptSize
  66.         );
  67.         for (i = 0; i < size; i += opSize) {
  68.             opSize = 2;
  69.             dcmd = ncrScriptPtr[i];
  70.             dsps = ncrScriptPtr[i + 1];
  71.             if (gScriptSetup) {
  72.                 dcmd = (dcmd);
  73.                 dsps = EndianSwap32Bit(dsps);
  74.             }
  75.             if (IsMemoryMoveOp(dcmd)) {
  76.                 temp = ncrScriptPtr[i + 2];
  77.                 if (gScriptSetup)
  78.                     temp = EndianSwap32Bit(temp);
  79.                 ++opSize;
  80.             }
  81.             pc = (i + opSize) * sizeof (UInt32);
  82.             printf("%03x %08lx %08lx",
  83.                 i * sizeof (UInt32),
  84.                 dcmd,
  85.                 dsps
  86.             );
  87.             if (IsMemoryMoveOp(dcmd))
  88.                 printf(" 08lx", temp);
  89.             if (gScriptSetup == FALSE
  90.              && ((dsps & 0xFF000000) >> 24) > ' '
  91.              && ((dsps & 0xFF000000) >> 24) <= '~') {
  92.                  isLabel = (dcmd == 0x80000000);
  93.                 printf("('%.4s')%s",
  94.                     &dsps,
  95.                     (isLabel) ? " <--" : ""
  96.                 );
  97.             }
  98.             if (gScriptSetup && HasLabel(dcmd)) {
  99.                 printf(" -> [%03x %4d]",
  100.                     dsps + pc,
  101.                     dsps + pc
  102.                 );
  103.             }
  104.             printf("\n");
  105.         }
  106. }
  107.  
  108. /*
  109.  * This must track HasLabel in the NCRRunScript.c
  110.  */
  111. Boolean
  112. HasLabel(
  113.         UInt32                    opcode
  114.     )
  115. {
  116.         Boolean                    result;
  117.         
  118.         switch (opcode & (bit31 | bit30)) {
  119.         case (0):                    /* 00 Block move instruction                    */
  120.             result = FALSE;
  121.             break;
  122.         case (bit30):                /* 01 I/O and read/write instructions            */
  123.             if ((opcode & (bit29 | bit28 | bit27)) == bit27)
  124.                 result = FALSE;        /* 01 001 Wait Disconnect takes no label        */
  125.             else if ((opcode & (bit29 | bit28 | bit27)) <= bit29)
  126.                 result = TRUE;        /* 01 000..100 are I/O instructions                */
  127.             else {
  128.                 result = FALSE;        /* 01 101..111 are read/write instructions        */
  129.             }
  130.             break;
  131.         case (bit31):                /* 10 Transfer Control instructions                */
  132.             switch (opcode & (bit29 | bit28 | bit27)) {
  133.             case 0:                    /* 10 000 Jump    (0x80000000 == NOP)                */
  134.             case bit27:                /* 10 001 Call                                    */
  135.             case bit28:                /* 10 010 Return                                */
  136.                 result = TRUE;
  137.                 break;
  138.             case (bit28 | bit27):    /* 10 011 Interrupt                                */
  139.             default:                /* 10 1xx Reserved                                */
  140.                 result = FALSE;
  141.                 break;
  142.             }
  143.             break;
  144.         case (bit31 | bit30):        /* 11 Memory Move                                */
  145.             result = FALSE;
  146.             break;
  147.         }
  148.         return (result);
  149. }
  150.  
  151.  
  152. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  153.  * TestFindDriverDeviceEntry
  154.  *
  155.  * Search for our driver's entry in the Name Registry. .
  156.  */
  157. OSErr
  158. GetDriverGlobalPtr(void)
  159. {
  160.         OSStatus                osStatus;
  161.         RegEntryIter            cookie;
  162.         Boolean                    done;
  163.         RegEntryID                deviceEntry;
  164.         RegPropertyValueSize    size;
  165.  
  166.         osStatus = RegistryEntryIterateCreate(&cookie);
  167.         if (osStatus != noErr)
  168.             fprintf(stderr, "RegistryEntryIterateCreate failed: %d\n", (int) osStatus);
  169.         if (osStatus == noErr) {
  170.             osStatus = RegistryEntrySearch(
  171.                         &cookie,
  172.                         kRegIterContinue,
  173.                         &deviceEntry,
  174.                         &done,
  175.                         "name",
  176.                         kPCIDeviceNameCString,    
  177.                         strlen(kPCIDeviceNameCString) + 1
  178.                     );
  179.             if (done != FALSE && osStatus == noErr)
  180.                 osStatus = paramErr;
  181.             RegistryEntryIterateDispose(&cookie);
  182.         } /* If we could create an iterator */
  183.         if (osStatus != noErr)
  184.             fprintf(stderr, "RegistryEntrySearch failed: %d\n", (int) osStatus);
  185.         if (osStatus == noErr) {
  186.             /*
  187.              * We have the registry entry for our device. Get the global pointer
  188.              */
  189.             size = sizeof gDriverGlobalPtr;
  190.             osStatus = RegistryPropertyGet(
  191.                         &deviceEntry,
  192.                         kDriverGlobalsPropertyName,
  193.                         (RegPropertyValue *) &gDriverGlobalPtr,
  194.                         &size
  195.                     );
  196.             (void) RegistryEntryIDDispose(&deviceEntry);
  197.             if (osStatus != noErr)
  198.                 fprintf(stderr, "RegistryPropertyGet failed: %d\n", (int) osStatus);
  199.         }
  200.         return ((OSErr) osStatus);
  201. }
  202.  
  203.  
  204.